; Owon ODP series of power supplies.
; 30 Dec 20  C GBY Add interface, update setup popup, create mode popup, restructure logging items to greatly speed up
; 10 May 20  B GBY Fix replaceText names in metadef's.

; Ethernet connection only.  TestController does not support USB unless LXi driver installed.
: Owon communications is very slow.  Measured communication speed is:
; Logging with just 3 channels of V, I can sustain 0.7 Sec sec intervals but every once in a while takes 1+ seconds.
; For shorter time lengths can log down to 0.4 sec intervals.
; Unfortunately, using individual commands for each item and logging too fast every so often items 
; become out of order/scrambled causing voltage number in current type error.

; TestController must be restarted before any changes in this file will be used.
; Manual is here: https://lygte-info.dk/project/TestControllerConfigDevice%20UK.html

; There are 3 triple output models in this series of power supplies.
; ODP6033: 60V/60V/6V at 3A/3A/3A
; ODP3033: 30V/30V/6V at 3A/3A/3A
; ODP3063: 30V/30V/6V at 6A/6A/3A

#metadef
#idString OWON,ODP3033,
#name Owon ODP3033
#handle ODP3033

#replaceText ChA_MaxVoltage 31
#replaceText ChB_MaxVoltage 31
#replaceText ChA_MaxCurrent 3.1
#replaceText ChB_MaxCurrent 3.1

#metadef
#idString OWON,ODP3063,
#name Owon ODP3063
#handle ODP3063

#replaceText ChA_MaxVoltage 31
#replaceText ChB_MaxVoltage 31
#replaceText ChA_MaxCurrent 6.1
#replaceText ChB_MaxCurrent 6.1

#metadef
#replaceText ChA_MaxVoltage 61
#replaceText ChB_MaxVoltage 61
#replaceText ChA_MaxCurrent 3.1
#replaceText ChB_MaxCurrent 3.1
#meta
#idString OWON,ODP6033,
#name Owon ODP6033
#handle ODP6033
#port 3000
#author gby
#notes Only Ethernet, not usb.  Very slow communications, 2.5 sec on average.

; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6) 
; Format: #value ColumnName Unit Format {Selector}
; Selector is only used when column layout varies with mode, this often require the use of #cmdMode
; This device is VERY slow so minimize the number of read items to speed it up.
;#value CH1_On - D0
;#value CH1_Voltage Vdc D3 
;#value CH1_Current Adc D3 
;#value CH1_Power Watt D3
;#value CH2_On - D0
;#value CH2_Voltage Vdc D3 
;#value CH2_Current Adc D3 
;#value CH2_Power Watt D3
;#value CH3_On - D0
;#value CH3_Voltage Vdc D3 
;#value CH3_Current Adc D3 
;#value CH3_Power Watt D3

#value CH1_Voltage Vdc D3
#value CH2_Voltage Vdc D3
#value CH3_Voltage Vdc D3
#value CH1_Current Adc D3
#value CH2_Current Adc D3
#value CH3_Current Adc D3

; How to poll for data, this is used for table and #values?
; a #askMode, #cmdMode and #prepareSample is used before this is string is used.
; Number of returned values must match number of columns defined with #value
; This is a single line command
;#askValues INST:SEL CH1;SOUR:CHAN:OUTP?;MEAS:VOLT?;MEAS:CURR?;MEAS:POW?;INST:SEL CH2;SOUR:CHAN:OUTP?;MEAS:VOLT?;MEAS:CURR?;MEAS:POW?;INST:SEL CH3;SOUR:CHAN:OUTP?;MEAS:VOLT?;MEAS:CURR?;MEAS:POW?
;#askValues INST:SEL CH1;MEAS:VOLT?;MEAS:CURR?;INST:SEL CH2;MEAS:VOLT?;MEAS:CURR?;INST:SEL CH3;MEAS:VOLT?;MEAS:CURR?
#askValues MEAS:VOLT:ALL?;MEAS:CURR:ALL?

; Format of answer: f=float, u=remove trailing letters, x=skip, *=Zero upper case values if this value is 0
;#askValuesReadFormat 

; Accept this delay when reading values (seconds)
#readingDelay 2

; Mode change have a longer delay on reading values (seconds)
#modeChangeDelay 10


; String to ask about actual meter mode, it is mostly used for DMM's
; This is a single line command
;#askMode 


; When one of these commands are used through the command interface a new configuration will be done before using #askMode
; Only one word for each #mayModifyMode
; Specify command without initial colon and in the shortest possible form
;#mayModifyMode 


; Prepare the meter to response to #askValues
;#prepareSample arm:sour imm;:arm:count 1;:trig:sour imm;:trig:count 1;:trig:samp:count 1;init

; Initial commands to meter when establishing connection, used to disable local control
;#initCmd  

; Final command to meter before breaking connection, used to restore local control
;#finalCmd 

; Used to turn output off for power supplies, generators and electronic loads
#outputOff OUTPUT:STATE off

;  **********  Generic Power Supply Interface  *******
;  Modeled after existing Keithley 2280 series power supply from 10/19/20
; Using multi-channel interface in scripts requires vars set for PS, PS:2, PS:3 in scripts.
; For example:
;  =var PS1=getDevice("PS")
;  =var PS2=getDevice("PS:2")

#interfaceType PS PS:2 PS:3

#interface setCHVoltage INST:SEL CH(channel);SOUR:VOLT (value)
#interface getCHVoltage INST:SEL CH(channel);SOUR:VOLT?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setCHCurrent INST:SEL CH(channel);SOUR:CURR (value)
#interface getCurrent INST:SEL CH(channel);SOUR:CURR?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setOVP INST:SEL CH(channel);SOUR:VOLT:LIM (value)
#interface getOVP INST:SEL CH(channel);SOUR:VOLT:LIM?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setOCP INST:SEL CH(channel);SOUR:CURR:LIM (value)
#interface getOCP INST:SEL CH(channel);SOUR:CURR:LIM?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setOn INST:SEL CH(channel);SOUR:CHAN:OUTP (value)
#interface getOn INST:SEL CH(channel);SOUR:CHAN:OUTP?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

#interface setAllOn OUTP:STATE (value)
#interface getAllOn OUTP:STATE?
:readmath: getMatch(value, "( |^)[-+.0-9].*")

;#interface SetTripReset ????

#interface setTrack OUTPUT:TRACK (value)
#interface getTrack OUTPUT:TRACK?

#interface setSeries OUTPUT:SERIES (value)
#interface getSeries OUTPUT:SERIES?

#interface setParallel OUTPUT:PARALLEL (value)
#interface getParallel OUTPUT:PARALLEL?

;  Pull values from #askValues used for logging.  Index goes 0 to n.
#interface readCH1Current 1
#interface readCH1Voltage 0
;#interface readCH1Watt 3
#interface readCH2Current 3
#interface readCH2Voltage 2
;#interface readCH1Watt 3
#interface readCH2Current 5
#interface readCH2Voltage 4
;#interface readCH1Watt 3

: *************  Mode Popup  ******************
#cmdModeLayout 1 3

#cmdMode _Indep_ _
OUTPUT:SERIES 0;OUTPUT:PARALLEL 0;OUTPUT:TRACK 0

#cmdMode _Series_ _
OUTPUT:SERIES 1

#cmdMode _Parallel_ _
OUTPUT:PARALLEL 1

; Voltage, current set points.

#cmdSetup number CH1_Voltage Settings
:read: INST:SEL CH1;SOUR:VOLT?
:write: INST:SEL CH1;SOUR:VOLT
Vdc  0 ChA_MaxVoltage

#cmdSetup number CH1_Current Settings
:read: INST:SEL CH1;SOUR:CURR?
:write: INST:SEL CH1;SOUR:CURR
Adc  0 ChA_MaxCurrent

#cmdSetup number CH2_Voltage Settings
:read: INST:SEL CH2;SOUR:VOLT?
:write: INST:SEL CH2;SOUR:VOLT
Vdc  0 ChB_MaxVoltage

#cmdSetup number CH2_Current Settings
:read: INST:SEL CH2;SOUR:CURR?
:write: INST:SEL CH2;SOUR:CURR
Adc  0 ChB_MaxCurrent

#cmdSetup number CH3_Voltage Settings
:read: INST:SEL CH3;SOUR:VOLT?
:write: INST:SEL CH3;SOUR:VOLT
Vdc  0 6.60

#cmdSetup number CH3_Current Settings
:read: INST:SEL CH3;SOUR:CURR?
:write: INST:SEL CH3;SOUR:CURR
Adc  0 3.10

; Voltage, current protection limit settings

#cmdSetup number CH1_Voltage Limits
:read: INST:SEL CH1;SOUR:VOLT:LIM?
:write: INST:SEL CH1;SOUR:VOLT:LIM
Vdc  0 ChA_MaxVoltage

#cmdSetup number CH1_Current Limits
:read: INST:SEL CH1;SOUR:CURR:LIM?
:write: INST:SEL CH1;SOUR:CURR:LIM
Adc  0 ChA_MaxCurrent

#cmdSetup number CH2_Voltage Limits
:read: INST:SEL CH2;SOUR:VOLT:LIM?
:write: INST:SEL CH2;SOUR:VOLT:LIM
Vdc  0 ChB_MaxVoltage

#cmdSetup number CH2_Current Limits
:read: INST:SEL CH2;SOUR:CURR:LIM?
:write: INST:SEL CH2;SOUR:CURR:LIM
Adc  0 ChB_MaxCurrent

#cmdSetup number CH3_Voltage Limits
:read: INST:SEL CH3;SOUR:VOLT:LIM?
:write: INST:SEL CH3;SOUR:VOLT:LIM
Vdc  0 6.60

#cmdSetup number CH3_Current Limits
:read: INST:SEL CH3;SOUR:CURR:LIM?
:write: INST:SEL CH3;SOUR:CURR:LIM
Adc  0 3.10

;#cmdSetup checkbox CH1_On
;:read: INST:SEL CH1;SOUR:CHAN:OUTP?
;:write: INST:SEL CH1;SOUR:CHAN:OUTP
;on 0 1

; Buttons to turn outputs on/off common to all tabs

#cmdSetup buttonsOn CH1_Output
:read: INST:SEL CH1;SOUR:CHAN:OUTP?
:write: INST:SEL CH1;SOUR:CHAN:OUTP
:color: (255,255,0)
:tip: Turn CH1 output on or off
:updatealloff:
Off 0
On 1

#cmdSetup buttonsOn CH2_Output
:read: INST:SEL CH2;SOUR:CHAN:OUTP?
:write: INST:SEL CH2;SOUR:CHAN:OUTP
:color: (0,204,255)
:tip: Turn CH2 output on or off
:updatealloff:
Off 0
On 1

#cmdSetup buttonsOn CH3_Output
:read: INST:SEL CH3;SOUR:CHAN:OUTP?
:write: INST:SEL CH3;SOUR:CHAN:OUTP
:color: (206,103,0)
:tip: Turn CH3 output on or off
:updatealloff:
Off 0
On 1

; Third tab Mode for independent, track, parallel, and/or series
; When in track mode will need to update tracked value setpoints

#cmdSetup checkbox Parallel Config
:read: OUTPUT:PARALLEL?
:write: OUTPUT:PARALLEL
:update: Series CH1_Current CH2_Current
:updatemodechange:
on 0 1

#cmdSetup checkbox Series Config
:read: OUTPUT:SERIES?
:write: OUTPUT:SERIES
:update: Parallel CH1_Voltage CH2_Voltage
:updatemodechange:
on 0 1

#cmdSetup checkbox Track Config
:read: OUTPUT:TRACK?
:write: OUTPUT:TRACK
:update: CH2_Voltage CH2_Current
:updatemodechange:
on 0 1